<?php
 //============================================================================
 // ____________________________PLIGG TEAM ADDON_______________________________
 //
// This CLASS was created by AnAlienHolakres3 ||| XXXXX  XX     XX XXXX   XXXX
// (c) 2007-2008                Jakub Holasek ||| XXXXX  XX     XX X      X
// @last_update                    01/22/2008 ||| XX     XX     XX X  XX  X  XX
// @version                              0.13 ||| XX     XXXXXX XX XXXXX  XXXXX
//
// This file can be used by Pligg community.
//=============================================================================

// Class membership contains general information about team members. 
// It means team member is normal user 

class Membership {
 
    var $team_id=Array ();
    var $user_id=0;
    
    var $read=true;
    
     //============================================================================
    //  Function read() gets membership data from database
    //============================================================================      
     function read() {
      global $db;
            
      $user_id = $this->user_id;
      
      
      if(($membership = $db->get_results("SELECT team_id FROM " . table_membership . "WHERE user_id= $user_id"))){
                          
        foreach ($membership as $teammember) {
         $team_id[] = $teammember->team_id;   
        }
         
         $this->read        = true;
         return true;                           
         }
         $this->read        = false;
         return false;                  
     }     
    
    //============================================================================
    //  Function store() saves membership data in database
    //============================================================================
    
    function store() {
        global $db;
          
        $team_id       = $this->team_id;
        $user_id       = $this->user_id;
                              
           $db->query("INSERT INTO " . table_membership . " (team_id, user_id) VALUES ($team_id, $user_id)");        
    }     
    
     //============================================================================
    //  Function duplicate_membership() finds out if user is already in team
    //============================================================================   
    
    function duplicate_membership($team_id,$user_id) {
        global $db;
        
        $team_id = $this->team_id;
        $user_id = $this->user_id;
        $task_name=$db->escape($task_name);
        $n = $db->get_var("SELECT count(*) FROM " . table_membership . " WHERE team_id= '$team_id' AND user_id = $user_id");
        return $n;
    }  
    
}                                        
?>